﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using RBS.Common;
using RBS.Core.BLL;
 

namespace RBS.Admin.tools
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class DicInfoTree : IHttpHandler, IRequiresSessionState
    {
        readonly SYS_DictInfo _bll = new SYS_DictInfo();
        public void ProcessRequest(HttpContext context)
        {
             
            //取得处事类型
            string action = RBSRequest.GetQueryString("action");
            switch (action)
            {
                case "dicinfotree": //验证扩展字段是否重复
                    get_dicinfo_tree(context);
                    break; 
            }
        }
        private void get_dicinfo_tree(HttpContext context)
        {
            IList<object> list = new List<object>();
            list.Add(new
            {
                id = 0,
                text = "数据字典",
                children = GetChildren(0)
            });
            string s = new JavaScriptSerializer().Serialize(list);
            s = s.Replace(",\"children\":[]", "");

            context.Response.Write(s); 
        }
        public IList<object> GetChildren(int parentId)
        { 
            DataTable dataTable=  _bll.GetList(" ParentID=" + parentId).Tables[0];
            IList<object> list = new List<object>();
            foreach (DataRow  c in dataTable.Rows)
            {
                list.Add(new
                {
                    id = c["DictID"],
                    text = c["DictName"],
                    children = GetChildren(Convert.ToInt32(c["DictID"]))
                });
            }
            return list;

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}